﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Multiprocessing.Core.Mathematics.Matrices
{
    public abstract class PartCollection<TPart> : IEnumerable<TPart> 
        where TPart : IMatrixPart
    {
        #region Properties

        public IMatrix Parent { get; private set; }

        public TPart this[int index] 
        {
            get { return GetItem(index); }
        }

        #endregion

        #region Constructors

        protected PartCollection(IMatrix parent)
        {
            if (ReferenceEquals(parent, null))
            {
                throw new ArgumentNullException("parent");
            }
            this.Parent = parent;
        }

        #endregion

        #region Methods

        protected abstract TPart GetItem(int index);

        #endregion

        public abstract IEnumerator<TPart> GetEnumerator();

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
